package TeachLesson;

import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "downloadFileServlet")
public class downloadFileServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
//实现文件下载
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("GBK");
        request.setCharacterEncoding("GBK");
        String filePath=request.getParameter("filePath");  //获取文件路径
        SmartUpload su=new SmartUpload();
        //初始化
        su.initialize(getServletConfig(),request,response);
        //下载
        try {
            su.downloadFile(filePath);
        } catch (SmartUploadException e) {
            e.printStackTrace();
        }
    }
}
